﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace DAL_EF
{
    public class StudentRepository : IStudentRepository
    {
        //public static string connectionString = ConfigurationManager.ConnectionStrings["projectbConnection"].ToString();
        private ProjectbEntities edm;

        /// <summary>
        /// select student for studentlist
        /// </summary>
        /// <param name="courseId"></param>
        /// <returns></returns>
        public List<Model.Student> selectStudent_Left(int courseId)
        {

            using (var edm = new ProjectbEntities())
            {

                var students =
                    (from s in edm.Students
                     select s).Except(from c in edm.CourseDetails
                                      join si in edm.Students
                                      on c.StudentId equals si.StudentId
                                      where c.CourseId == courseId
                                      select si);
                return EntityConverter.ToModelStudent(students.ToList<Student>());

            }
        }
        /// <summary>
        /// select student for selected list
        /// </summary>
        /// <param name="courseId"></param>
        /// <returns></returns>
        public List<Model.Student> selectStudent_Right(int courseId)
        {
            using (var edm = new ProjectbEntities())
            {
                var students = (from cd in edm.CourseDetails
                                join s in edm.Students
                                on cd.StudentId equals s.StudentId
                                where cd.CourseId == courseId
                                select s).ToList<Student>();

                return EntityConverter.ToModelStudent(students);
            }
        }
    }
}

